import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import { setupRouterGuard } from './guard'

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'Basic',
    component: () => import('@/layouts/BasicLayout.vue'),
    children: [
      {
        path: '/user/:id',
        name: 'UserDetail',
        component: () => import('@/pages/user/UserDetailPage.vue'),
        meta: {
          menu: { openKey: 'System', selectedKey: 'UserList' },
        },
      },
      {
        path: '/role/:id',
        name: 'RoleDetail',
        component: () => import('@/pages/role/RoleDetailPage.vue'),
        meta: {
          menu: { openKey: 'System', selectedKey: 'RoleList' },
        },
      },
      {
        path: '/role/:id/assign-menus',
        name: 'AssignMenu',
        component: () => import('@/pages/role/AssignMenuPage.vue'),
        meta: {
          menu: { openKey: 'System', selectedKey: 'RoleList' },
        },
      },
      {
        path: '/role/:id/assign-permissions',
        name: 'AssignPermission',
        component: () => import('@/pages/role/AssignPermissionPage.vue'),
        meta: {
          menu: { openKey: 'System', selectedKey: 'RoleList' },
        },
      },
      {
        path: '/system-message/:id',
        name: 'SystemMessageDetail',
        component: () => import('@/pages/system/SystemMessageDetailPage.vue'),
        meta: {
          menu: { openKey: 'System', selectedKey: 'SystemMessage' },
        },
      },
      {
        path: '/doctor/:id',
        name: 'DoctorDetail',
        component: () => import('@/pages/doctor/DoctorDetailPage.vue'),
        meta: {
          menu: { openKey: 'BasicData', selectedKey: 'Doctor' },
        },
      },
      {
        path: '/doctor/:id/doctor-share-rule',
        name: 'DoctorShareRule',
        component: () => import('@/pages/doctor/DoctorShareRulePage.vue'),
        meta: {
          menu: { openKey: 'Doctor', selectedKey: 'DoctorList' },
        },
      },
      {
        path: '/sales/invoice/:id',
        name: 'InvoiceDetail',
        component: () => import('@/pages/sale/InvoiceDetailPage.vue'),
        meta: {
          menu: { openKey: 'SalesCommission', selectedKey: 'Invoice' },
        },
      },
      {
        path: '/monthly-stat/:id',
        name: 'MonthlyStatDetail',
        component: () => import('@/pages/sale/MonthlyStatDetailPage.vue'),
        meta: {
          menu: { openKey: 'SalesCommission', selectedKey: 'MonthlyStat' },
        },
      },
      {
        path: '/commission/:id',
        name: 'CommissionDetail',
        component: () => import('@/pages/commission/CommissionMonthDetailPage.vue'),
        meta: {
          menu: { openKey: 'SalesCommission', selectedKey: 'CommissionList' },
        },
      },
      {
        path: '/bonus/:id',
        name: 'BonusDetail',
        component: () => import('@/pages/bonus/BonusDetailPage.vue'),
        meta: {
          menu: { openKey: 'Bonus', selectedKey: 'BonusList' },
        },
      },
      {
        path: '/bonus-setting/:id',
        name: 'BonusSettingDetail',
        component: () => import('@/pages/bonus/BonusSettingDetailPage.vue'),
        meta: {
          menu: { openKey: 'Bonus', selectedKey: 'BonusSetting' },
        },
      },
      {
        path: '/promotion/:id',
        name: 'PromotionDetail',
        component: () => import('@/pages/consult_rule/PromotionDetailPage.vue'),
        meta: {
          menu: { openKey: 'ConsultRule', selectedKey: 'Promotion' },
        },
      },
      {
        path: '/reduction-plan/:id',
        name: 'RedictionPlanDetail',
        component: () => import('@/pages/consult_rule/RedictionPlanDetailPage.vue'),
        meta: {
          menu: { openKey: 'ConsultRule', selectedKey: 'RedictionPlan' },
        },
      },
      {
        path: '/consult-plan/:id',
        name: 'ConsultPlanDetail',
        component: () => import('@/pages/consult_rule/ConsultPlanDetailPage.vue'),
        meta: {
          menu: { openKey: 'ConsultRule', selectedKey: 'ConsultPlan' },
        },
      },
      {
        path: '/regular_share/:id',
        name: 'RegularShareDetail',
        component: () => import('@/pages/share_rule/RegularShareDetailPage.vue'),
        meta: {
          menu: { openKey: 'ShareRule', selectedKey: 'Regular' },
        },
      },
      {
        path: '/extra_share/:id',
        name: 'ExtraShareDetail',
        component: () => import('@/pages/share_rule/ExtraShareDetailPage.vue'),
        meta: {
          menu: { openKey: 'ShareRule', selectedKey: 'Extra' },
        },
      },
    ],
  },
  { path: '/login', name: 'Login', component: () => import('@/pages/LoginPage.vue') },
  {
    path: '/:pathMatch(.*)*',
    name: 'NotFound',
    component: () => import('@/pages/Notfound.vue'),
  },
  {
    path: '/error',
    name: 'Error',
    component: () => import('@/pages/ErrorPage.vue'),
  },
]

const router = createRouter({
  history: createWebHistory(''),
  routes,
})

// 设置路由守卫,动态添加路由
setupRouterGuard(router)

export default router
